<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getServerName() + ":"
            + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>数据查看</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">

</head>
<%@include file="../include/header.jsp" %>
<body>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <input type="hidden" id="endTime"
           value="<fmt:formatDate value='${activity.endTime}' pattern='yyyy-MM-dd HH:mm:ss'/>"/>
    <section>
        <div class="section-main">
            <%--联合发起--->众筹--->支持者列表--%>
            <div class="layui-tab layui-tab-brief mt20">
                <ul class="layui-tab-title">
                    <c:choose>
                        <c:when test="${isMultiple == true}">
                            <li>众筹<span class="pl5">${activity.joinNum}</span>人</li>
                            <li class="layui-this">联合发起<span class="pl5">${activity.representNum}</span>人</li>
                        </c:when>
                        <c:otherwise>
                            <li class="" id="funding">众筹<span id="total_1" class="pl5">${crowdfundNum}</span>人</li>
                            <li class="layui-this" id="representing">联合发起<span id="total_0"
                                                                               class="pl5">${activity.representNum}</span>人
                            </li>
                            <li class="" id="directPay">直接付款<span id="total_2" class="pl5">${directPayNum}</span>人</li>
                            <li>转入<span class="pl5">${transferNum}</span>人</li>
                        </c:otherwise>
                    </c:choose>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item  ">
                        <div class="act-main-body img-text-content">
                            ${activityDetail.content}
                        </div>
                    </div>
                    <div class="layui-tab-item  layui-show">
                        <form class="layui-form" action="${ctx}/crowdfund/support/listForRepresent.do" id="myForm"
                              method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>
                            <input type="hidden" name="id" id="id" value="${activity.id}"/>
                            <input name="projectId" value="${projectId}" type="hidden">
                            <input name="name" value="${name}" type="hidden">
                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item"><label class="search-form-lable">支付状态</label>
                                            <div class="check-btn-inner">
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),'','#myForm')" ${empty supportWithMember.payStatus ? 'class="active"' : ''}>全部</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),0,'#myForm')" ${supportWithMember.payStatus == 0 ? 'class="active"' : ''}>待支付</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),1,'#myForm')" ${supportWithMember.payStatus == 1 ? 'class="active"' : ''}>支付成功</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),2,'#myForm')" ${supportWithMember.payStatus == 2 ? 'class="active"' : ''}>退款中</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),3,'#myForm')" ${supportWithMember.payStatus == 3 ? 'class="active"' : ''}>退款成功</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),4,'#myForm')" ${supportWithMember.payStatus == 4 ? 'class="active"' : ''}>退款失败</a>
                                                <input type="hidden" name="payStatus"
                                                       value="${supportWithMember.payStatus}"/>
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">商户</label>
                                            <div class="layui-input-inline">
                                                <select name="merchantId">
                                                    <option value="">全部</option>
                                                    <c:forEach var="merchant" items="${wechatMerchants}">
                                                        <option value="${merchant.merchantId}" ${merchantId == merchant.merchantId ? 'selected' : ''}>${merchant.merchantName}</option>
                                                    </c:forEach>
                                                </select>
                                            </div>
                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item-inline"><label class="search-form-lable"
                                                                            style="text-indent: 13px;">支持者</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="favorerName" autocomplete="off"
                                                       class="layui-input"
                                                       value="${supportWithMember.favorerName}"
                                                       placeholder="支持者">
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label
                                                class="search-form-lable">联系电话</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="favorerMobile" autocomplete="off"
                                                       class="layui-input"
                                                       value="${supportWithMember.favorerMobile}"
                                                       placeholder="联系电话">
                                            </div>
                                        </li>
                                        <li class="form-item-inline">
                                            <div class="sub-btns">
                                                <a class="layui-btn layui-btn-danger"
                                                   href="javascript:submitFunction('#myForm')">查询</a>
                                                <a class="layui-btn layui-btn-normal"
                                                   href="javascript:resetFunction('#myForm')">重置</a>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </form>
                        <form class="layui-form" action="${ctx}/crowdfund/support/listForRepresentExport.do"
                              id="exportForm" method="post">
                            <input name="projectId" value="${projectId}" type="hidden">
                            <input type="hidden" name="name" value="${name}">
                        </form>
                        <div class="my-act-list-content">
                            <ul class="num">
                                <div class="l">
                                    <li class="f16">【${name}】的众筹的支持人数<span class="red">${page.totalCount}</span>人</li>
                                </div>
                                <div class="r">
                                    <li style="cursor: pointer;" class="r">
                                        <a class="layui-btn layui-btn-danger layui-btn-sm" id="revise">校正</a>
                                    </li>
                                    <c:if test="${isCan}">
                                        <li style="cursor: pointer;" class="r">
                                            <a class="layui-btn layui-btn-danger layui-btn-sm" id="refundAll">全部退款</a>
                                        </li>
                                    </c:if>
                                    <li style="cursor: pointer;" class="r">
                                        <a class="layui-btn layui-btn-danger layui-btn-sm" id="btnExport">导出EXCEL</a>
                                    </li>
                                </div>
                                <p class="cl"></p>
                            </ul>
                            <div class="cl">
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="8%">
                                        <col width="10%">
                                        <col width="8%">
                                        <col width="8%">
                                        <col width="8%">
                                        <col width="8%">
                                        <col width="10%">
                                        <col width="8%">
                                    </colgroup>
                                    <thead>
                                    <tr>
                                        <th>支持者</th>
                                        <th>公司</th>
                                        <th>职务</th>
                                        <th>联系电话</th>
                                        <th>支持金额</th>
                                        <th>状态</th>
                                        <th>商户名称</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach var="directPay" items="${list}">
                                        <tr>
                                            <td class="table-member"
                                                onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${directPay.favorerId}','400px','470px')">
                                                <div class="member-cell">
                                                    <div class="member-logo common-img">
                                                        <img src="<c:if test="${directPay.favorerLogo != null}">${directPay.favorerLogo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                             alt="" onerror="txz.errImg(this)"
                                                             onload="txz.imgLoad(this)">
                                                    </div>
                                                    <div class="member-name ellipsis-1"><a class="blue"
                                                                                           title="${directPay.favorerName}"
                                                                                           href="javascript:void(0);">${directPay.favorerName}</a>
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <div class="ellipsis-1"
                                                     title="${directPay.favorerCompany}">${directPay.favorerCompany}</div>
                                            </td>
                                            <td>
                                                    ${directPay.favorerJobTitle}
                                            </td>
                                            <td>
                                                    ${directPay.favorerMobile}
                                            </td>
                                            <td>
                                                <fmt:formatNumber pattern="0.00" value="${directPay.payment}"/>
                                            </td>
                                            <td>
                                                <c:if test="${directPay.payStatus == 0}">
                                                    <a class="blue" title="待支付"
                                                       href="javascript:openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${directPay.orderId}','450px','570px')">待支付</a>
                                                </c:if>
                                                <c:if test="${directPay.payStatus == 1}">
                                                    <a class="blue" title="支付成功"
                                                       href="javascript:openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${directPay.orderId}','450px','570px')">支付成功</a>
                                                </c:if>
                                                <c:if test="${directPay.payStatus == 2}">
                                                    <a class="blue" title="退款中"
                                                       href="javascript:openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${directPay.orderId}','450px','570px')">退款中</a>
                                                </c:if>
                                                <c:if test="${directPay.payStatus == 3}">
                                                    <a class="blue" title="退款成功"
                                                       href="javascript:openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${directPay.orderId}','450px','570px')">退款成功</a>
                                                </c:if>
                                                <c:if test="${directPay.payStatus == 4}">
                                                    <a class="blue" title="退款失败"
                                                       href="javascript:openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${directPay.orderId}','450px','570px')">退款失败</a>
                                                </c:if>
                                            </td>
                                            <td>
                                                    ${directPay.merchantName}
                                            </td>
                                            <td class="tb-opts">
                                                <div class="comm-opts">
                                                    <c:if test="${isCan}">
                                                    <c:if test="${directPay.payStatus == 1 || directPay.payStatus == 4}">
                                                        <a href="javascript:refund('${directPay.id}');"
                                                           target="_self">
                                                            退款
                                                        </a>
                                                    </c:if>
                                                    </c:if>
                                                </div>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div id="page_content" class="page-container"></div>
                    </div>
                    <div class="layui-tab-item ">

                    </div>
                </div>
            </div>
        </div>
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/common-refund.js"></script>
<script type="text/javascript">
    const regex = /^[a-zA-Z0-9]{6,20}$/;
    var laytpl = null;
    var laypage = null;
    var element = null;
    var loadIndexMy = null;

    txz.initHeader({
        nav: [{
            name: '众筹项目管理',
            href: '${ctx}/activity/activity/zcActivityList.do',
        }, {
            name: '${activity.title}'
        }, {
            name: '数据查看',
            curr: true
        }],
        info: '<span class="f12">共<b>${page.totalCount}</b>条记录',
        btns: [{
            type: 'add',
            name: '返回',
            icon: 'back',
            href: 'javascript:window.history.back()'
        }]
    });

    var times = 1;

    $(function () {

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });

        if (${isMultiple == true}) {
            $("#myForm").attr('action', '${ctx}/activityMultiple/support/activity/listForRepresent.do');
        }

        layui.use(['laytpl', 'laypage', 'element', 'form'], function () {
            laytpl = layui.laytpl;
            laypage = layui.laypage;
            element = layui.element;


            element.on('tab', function (data) {
                if (${isMultiple == true}) {
                    if (data.index == 0) {
                        window.location.href = "${ctx}/activityMultiple/project/listForActivity.do?id=${activity.id}";
                    } else if (data.index == 1) {
                        window.location.href = "${ctx}/activityMultiple/represent/listForActivity.do?id=${activity.id}";
                    }
                } else {
                    if (data.index == 0) {
                        window.location.href = "${ctx}/activity/activity/zcCrowdfundList.do?id=${activity.id}";
                    } else if (data.index == 1) {
                        window.location.href = "${ctx}/activity/activity/zcRepresentList.do?id=${activity.id}";
                    } else if (data.index == 2) {
                        window.location.href = "${ctx}/activity/activity/zcDirectPayList.do?id=${activity.id}";
                    }
                }
            });

            var form = layui.form;
            form.verify({
                oldPassword: function (value) {
                    if (value == "") {
                        return "原退款密码不能为空";
                    } else if (!regex.test(value)) {
                        return "原退款密码格式不正确";
                    }
                },
                newPassword: function (value) {
                    if (value == "") {
                        return "新退款密码不能为空";
                    } else if (!regex.test(value)) {
                        return "新退款密码格式不正确";
                    }
                },
                confirmPassword: function (value) {
                    var pwd = $("#findpwd_form").find("[name=newPassword]").val();
                    if (value == "") {
                        return "确认密码不能为空";
                    } else if (!regex.test(value)) {
                        return "确认密码格式不正确";
                    } else if (pwd != value) {
                        return "确认密码与新密码不匹配";
                    }
                }
            });
        });

        $("#cancel_btn").click(function () {
            $(this).closest('.f-def-dialog').fadeOut();
        });

        $("#btnExport").click(function () {
            layer.confirm('确认要导出Excel吗?', {
                icon: 3,
                title: '系统提示'
            }, function (index) {
                var url = $("#exportForm").attr("action");
                var loadIndex = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
                var params = $("#exportForm").serializeArray();
                params.push({
                    name: 'merchantId',
                    value: $("[name=merchantId]").find("option:selected").val()
                });
                $.post(url, params, function (res) {
                    top.layer.close(loadIndex);
                    if (res.success) {
                        window.location.href = res.data;
                    } else {
                        util.layerMsgError(res.description)
                    }
                });
                top.layer.close(index);
            });
        });

        $("#revise").click(function () {
            var loadIndex = layer.msg('玩命校正中,请耐心等待...', {
                icon: 16,
                shade: 0.1,
                time: 0
            });
            $.post("${ctx}/crowdfund/project/revise.do", {
                id: "${projectId}"
            }, function (data) {
                if (data.success == true) {
                    util.layerAlertSuccess("校正成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerAlertError("校正失败")
                }
                top.layer.close(loadIndex);
            });
        });

        $("#refundAll").click(function () {
            txzRefund.doRefundOpt('${ctx}/crowdfund/project/refund.do', {
                id: "${projectId}"
            }, '${activity.id}')
        });
        util.initWebSocket(function (event) {
            top.layer.close(loadIndexMy);
            if (times == 1) {
                layer.alert(event.data, {
                    icon: 6,
                    closeBtn: 0
                }, function (index) {
                    window.location.reload();
                });
                times++;
            }
        });
    })

    function refund(id) {
        txzRefund.doRefundOpt('${ctx}/crowdfund/support/refund.do', {
            id: id
        }, '${activity.id}')
    }
</script>
</body>
</html>
